import apiRequest from '@/utils/apiRequest'

// 获取销售合同列表
export function getSalesContractList(params) {
  return apiRequest.get('/SalesContracts', { params });
}

// 获取销售合同详情
export function getSalesContractDetail(id) {
  return apiRequest.get(`/SalesContracts/${id}`);
}

// 创建销售合同
export function createSalesContract(data) {
  return apiRequest.post('/SalesContracts', data);
}

// 更新销售合同
export function updateSalesContract(id, data) {
  return apiRequest.put(`/SalesContracts/${id}`, data);
}

// 删除销售合同
export function deleteSalesContract(id) {
  return apiRequest.delete(`/SalesContracts/${id}`);
}

// 审核销售合同
export function approveSalesContract(id, approvedBy) {
  return apiRequest.put(`/SalesContracts/${id}/approve`, null, {
    params: { approvedBy }
  });
}

// 终止销售合同
export function terminateSalesContract(id, terminatedBy, reason) {
  return apiRequest.put(`/SalesContracts/${id}/terminate`, null, {
    params: { reason, terminatedBy }
  });
}

// 批量审核销售合同 (后端暂未实现)
// export function batchApproveSalesContracts(ids, data) {
//   return request.post('/SalesContracts/batch-audit', {
//     ids,
//     ...data
//   });
// }

// 批量终止销售合同 (后端暂未实现)
// export function batchTerminateSalesContracts(ids, data) {
//   return request.post('/SalesContracts/batch-terminate', {
//     ids,
//     ...data
//   });
// }

// 获取合同条款模板列表
export function getTermTemplateList(params) {
  return apiRequest.get('/ContractTemplates', { params });
}

// 获取合同条款模板详情
export function getTermTemplateDetail(id) {
  return apiRequest.get(`/ContractTemplates/${id}`);
}